﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Web;
using System.Net;
using System.IO;
using System.Data;
using System.Text;
using System.Xml;
using System.Threading;
using CE.InputOut;
using CE.Database;

/// <summary>
/// Summary description for WegoFlights
/// </summary>
/// 
namespace CE.Wego
{
    public class WegoFlights
    {
        const string API_KEY = "c08b4c9e";
        public WegoFlights()
        {
            //
            // TODO: Add constructor logic here
            //
        }

        public DataSet CheckAPIUsage()
        {
            DataSet _ds = new DataSet();
            string _result = "";

            try
            {

                HttpWebRequest req = (HttpWebRequest)WebRequest.Create(@"http://www.wego.com/api/flights/usage.html? " + @"&apiKey=" + API_KEY + "&format=xml");

                //http://www.wego.com/api/flights/usage.html?format=json&apikey=testapikey
                req.Method = "get";
                req.Referer = "http://www.comparexpress.com";
                HttpWebResponse webresponse = (HttpWebResponse)req.GetResponse();
                Stream stream = webresponse.GetResponseStream();
                StreamReader answer = new StreamReader(stream);
                _ds = new DataSet("dslist");
                _ds.ReadXml(stream);

                //_result = GetResponse("http://www.wego.com/api/flights/usage.html?apiKey=" + API_KEY + "&format=xml");



            }
            catch (WebException Wex)
            {
                CreateExceptionLog(Wex, "string CheckAPIUsage()");
            }
            catch (ThreadAbortException Tex)
            {
                //do nothing
            }
            catch (Exception Ex)
            {
                CreateExceptionLog(Ex, "string CheckAPIUsage()");
            }
            return _ds;

        }

        public DataSet SearchFlight(string fromLocation, string toLocation, string tripType, string cabinClass, string inboundDate, string outboundDate, string numAdults, string numChild)
        {
            DataSet _ds = null;

            try
            {
                HttpWebRequest req = (HttpWebRequest)WebRequest.Create(@"http://www.wego.com/api/flights/startSearch.html? " + @"&apiKey=" + API_KEY + "&format=xml&"
                    + "fromLocation=" + fromLocation + "&toLocation=" + toLocation + "&tripType=" + tripType + "&cabinClass=" + cabinClass + "&inboundDate=" + inboundDate + "&outboundDate=" + outboundDate + "&numAdults=" + numAdults + "&numChildren=" + numChild + "&ts_code=ae2c7");
                //http://www.wego.com/api/flights/startSearch.html?format=json&fromLocation=SIN&toLocation=BKK&tripType=roundTrip&cabinClass=Economy&inboundDate=2010-06-26&outboundDate=2010-06-23&numAdults=1&apiKey=testApiKey
                req.Method = "GET";
                req.Referer = "http://www.comparexpress.com";
                HttpWebResponse webResponse = (HttpWebResponse)req.GetResponse();
                Stream stream = webResponse.GetResponseStream();
                StreamReader answer = new StreamReader(stream);
                _ds = new DataSet("DsList");
                _ds.ReadXml(stream);
            }
            catch (WebException Wex)
            {
                CreateExceptionLog(Wex, "string SearchFlight(string fromLocation, string toLocation, string tripType, string cabinClass, string inboundDate, string outboundDate, string numAdults)");
            }
            catch (ThreadAbortException Tex)
            {
                //do nothing
            }
            catch (Exception Ex)
            {
                CreateExceptionLog(Ex, "string SearchFlight(string fromLocation, string toLocation, string tripType, string cabinClass, string inboundDate, string outboundDate, string numAdults)");
            }
            return _ds;
        }

        public double GetExchangeRates(string currency, double amount)
        {
            string _result = "";
            double _SGDrate = 0;

            try
            {
                HttpWebRequest req = (HttpWebRequest)WebRequest.Create(@"http://media.wego.com/js/bezurk/1.0/currency_rates.js? " + @"&date=" + CE.Global.General.GetUTCDateTime().ToString("YYYYMMdd"));
                req.Method = "GET";
                req.Referer = "http://www.comparexpress.com";
                HttpWebResponse webResponse = (HttpWebResponse)req.GetResponse();
                Stream stream = webResponse.GetResponseStream();
                StreamReader answer = new StreamReader(stream);
                _result = answer.ReadToEnd();

                _result = _result.Remove(0, 21);

                string[] _rates = _result.Replace("}\n;", "").Split(',');
                double currentrate = 0;

                for (int i = 0; i < _rates.Length; i++)
                {
                    string _currency = _rates[i].Substring(1, 3).Trim();

                    if (currency == _currency)
                    {
                        currentrate = double.Parse(_rates[i].Remove(0, 6).Trim());
                        _SGDrate = Math.Round((amount / currentrate), 2);
                        break;
                    }

                }


            }
            catch (WebException Wex)
            {
                CreateExceptionLog(Wex, "string GetExchangeRates(string currency, double amount)");
            }
            catch (ThreadAbortException Tex)
            {
                //do nothing
            }
            catch (Exception Ex)
            {
                CreateExceptionLog(Ex, "string GetExchangeRates(string currency, double amount) " + _result.ToString());
            }

            return _SGDrate;
        }

        private int RandomNumber()
        {
            int min = 1;
            int max = 2147483647;

            Random random = new Random();
            return random.Next(min, max);
        }

        public bool GetFlightResults(string instanceId, bool isRoundTrip, string outbounddate, string inbounddate, string viewid, int callcount, int _randomvalue, DateTime _timeStart)
        {
            string _result = "";
            bool isdone = false;

            if (_randomvalue == 0)
            {
                _randomvalue = RandomNumber();
            }


            try
            {
                DateTime _timeEnd = new DateTime();

                _result = GetResponse("http://www.wego.com/api/flights/pull.html?apiKey=" + API_KEY + "&format=xml&instanceId=" + instanceId + "&rand=" + _randomvalue.ToString());

                int i = 0;
                int retrieveMaxSeconds = 10;

                System.Threading.Thread.Sleep(5000);

                _timeEnd = CE.Global.General.GetUTCDateTime();
                TimeSpan _ts = _timeEnd.Subtract(_timeStart);
                if (_ts.Seconds <= retrieveMaxSeconds)
                {
                    if (_result.Substring(_result.IndexOf("pendingResults>") + 15, 4) == "true")
                    {
                        _result = (GetResponse("http://www.wego.com/api/flights/pull.html?apiKey=" + API_KEY + "&format=xml&instanceId=" + instanceId + "&rand=" + _randomvalue.ToString())).Replace("</response>", "").Replace("</itineraries>", "")
                            + _result.Remove(0, 102); //103

                        i = 1;

                        //loop until data is complete
                        //while (_result.Substring(_result.IndexOf("pendingResults>") + 15, 4) == "true")
                        //{
                        //    _timeEnd = CE.Global.General.GetUTCDateTime();
                        //    TimeSpan _ts = _timeEnd.Subtract(_timeStart);

                        //    if (_ts.Seconds >= retrieveMaxSeconds)
                        //    {
                        //        break;
                        //    }

                        //    if (i > 0) //max400
                        //    {
                        //        break;
                        //    }

                        //    _result = (GetResponse("http://www.wego.com/api/flights/pull.html?apiKey=" + API_KEY + "&format=xml&instanceId=" + instanceId + "&rand=" + _randomvalue.ToString())).Replace("</response>", "").Replace("</itineraries>", "")
                        //        + _result.Remove(0, 103);

                        //    i++;
                        //}

                    }
                    else
                    {
                        //Call Again
                        GetFlightResults(instanceId, isRoundTrip, outbounddate, inbounddate, viewid, callcount + 1, _randomvalue, _timeStart);
                    }

                }


                //else if (_result.Length > 129)
                //{
                //    //1 call result only
                //    i = 1;
                //}

                //int noOfAttempts = 7; //test max 1600 results
                //call api max 8 times
                //if (_result.Substring(_result.IndexOf("pendingResults>") + 15, 4) == "true")
                //{
                //    for (int icount = 0; icount < noOfAttempts; icount++)
                //    {
                //        _result = (GetResponse("http://www.wego.com/api/flights/pull.html?apiKey=" + API_KEY + "&format=xml&instanceId=" + instanceId + "&rand=" + _randomvalue.ToString())).Replace("</response>", "").Replace("</itineraries>", "")
                //       + _result.Remove(0, 103);

                //        i++;
                //        if (_result.Substring(_result.IndexOf("pendingResults>") + 15, 4) != "true")
                //        {
                //            break;
                //        }
                //    }
                //}
                //else
                //{
                //    if (_result.Length > 129)
                //    {
                //        //1 call result only
                //        i = 1;
                //    }
                //}

                // just one call
                //if (_result.Length <= 129)
                //{
                //    i = 0;
                //}
                //else
                //{
                //    i = 1;
                //}

                //_timeEnd = CE.Global.General.GetUTCDateTime();
                //TimeSpan _ts2 = _timeEnd.Subtract(_timeStart);

                //if (_ts2.Seconds < retrieveMaxSeconds)
                //{

                //    //if (i == 0) //1 call
                //    if (i == 0 && _result.Substring(_result.IndexOf("pendingResults>") + 15, 4) != "true") //more than 1 call                
                //    {
                //        //String[] _fileContent = new String[6];
                //        //_fileContent[0] = "callcount : " + callcount.ToString();
                //        //_fileContent[1] = "Date Time : " + CE.Global.General.GetUTCDateTime().ToString();
                //        //_fileContent[2] = "result xml :" + _result.Substring(_result.IndexOf("pendingResults>") + 15, 4);
                //        //_fileContent[3] = "ran val : " + _randomvalue.ToString();
                //        //_fileContent[4] = "Location : " + "CE.Database.MyDatabase - test";
                //        //_fileContent[5] = "Message : " + i.ToString();

                //        //WriteExceptionLog("WegoTest" + _randomvalue.ToString() + "-" + callcount.ToString() + "_", _fileContent);

                //        if (callcount <= 5)
                //        {
                //            System.Threading.Thread.Sleep(5000);
                //            GetFlightResults(instanceId, isRoundTrip, outbounddate, inbounddate, viewid, callcount + 1, _randomvalue, _timeStart);
                //        }
                //    }
                //}

                isdone = FlightsResultsXMLtoTable(_result, instanceId, isRoundTrip, outbounddate, inbounddate, viewid);

                WegoFlightsDB wegodb = new WegoFlightsDB();

                wegodb.UpdateSearch(Convert.ToInt64(viewid), _randomvalue);

                //isdone = FlightsToXML(_result, instanceId, isRoundTrip, outbounddate, inbounddate, viewid);
            }
            catch (WebException Wex)
            {
                CreateExceptionLog(Wex, "DataSet GetFlightResults(string instanceId)");
            }
            catch (ThreadAbortException Tex)
            {
                //do nothing
            }
            catch (Exception Ex)
            {
                CreateExceptionLog(Ex, "DataSet GetFlightResults(string instanceId)");
            }

            return isdone;

        }

        public bool FlightsToXML(string results, string instanceId, bool isRoundTrip, string outbounddate, string inbounddate, string viewid)
        {
            bool isDone = false;

            XmlDocument xdoc = new XmlDocument();

            try
            {
                xdoc.LoadXml(results);

                string xmlfilename = GetFilePath() + "search_" + viewid + "_" + ".xml";
                xdoc.Save(xmlfilename);
                isDone = true;

                //DataSet dsResults = XMLToDS(xmlfilename);
                isDone = FlightsResultsXMLtoTable(xmlfilename, instanceId, isRoundTrip, outbounddate, inbounddate, viewid);
            }
            catch (Exception Ex)
            {
                isDone = false;
                CreateExceptionLog(Ex, "bool FlightsToXML");
            }


            return isDone;
        }

        private string GetFilePath()
        {
            string _filePath = CE.Configuration.MyConfigurationManager.GetAppSettingValue("FileOutputPath").ToString();
            _filePath += "xmloutput\\wegoflights\\";
            CE.InputOut.MyIO _myIO = new CE.InputOut.MyIO();
            string _todaydate = CE.Global.General.GetUTCDateTime().ToString("yyyyMMMdd");
            if (!_myIO.CheckDirectory(_filePath + _todaydate))
            {
                if (_myIO.CreateDirectory(_filePath, _todaydate))
                {
                    _filePath += _todaydate + "\\";
                }
            }
            else
            {
                _filePath += _todaydate + "\\";
            }

            return _filePath;
        }

        private DataSet XMLToDS(string xmlfilename)
        {
            XmlTextReader reader = new XmlTextReader(xmlfilename);

            DataSet ds = new DataSet();
            ds.ReadXml(reader);

            /* ds TABLES:
             * [0]	{response}	object {System.Data.DataTable}
     +		[1]	{itineraries}	object {System.Data.DataTable}
     +		[2]	{itinerary}	object {System.Data.DataTable}
     +		[3]	{carrier}	object {System.Data.DataTable}
     +		[4]	{e}	object {System.Data.DataTable}
     +		[5]	{inboundInfo}	object {System.Data.DataTable}
     +		[6]	{aircraftTypes}	object {System.Data.DataTable}
     +		[7]	{airports}	object {System.Data.DataTable}
     +		[8]	{flightClasses}	object {System.Data.DataTable}
     +		[9]	{flightNumbers}	object {System.Data.DataTable}
     +		[10]	{location}	object {System.Data.DataTable}
     +		[11]	{outboundInfo}	object {System.Data.DataTable}
     +		[12]	{price} 
             */

            foreach (DataTable tbl in ds.Tables)
            {
                foreach (DataRow dr in tbl.Rows)
                {
                    // for (...){...}
                }


                //save to table
            }

            return ds;

        }

        public bool FlightsResultsXMLtoTable(string results, string instanceId, bool isRoundTrip, string outbounddate, string inbounddate, string viewid)
        {
            bool isDone = false;
            //DataSet _dsFlights = new DataSet();
            //DataTable _dtflights = new DataTable();
            //DataTable _dtairloc = new DataTable();

            //_dtflights = FlightsTable();
            //DataRow dr;
            //_dtairloc = AirportLocationTable();
            //DataRow drairloc;

            WegoFlightsDB wegodb = new WegoFlightsDB();
            WegoFlightsInfo wegoinfo = new WegoFlightsInfo();

            #region stringvar

            string BookingCode = "";

            string Airlines = "";
            string AirlineCode = "";
            string Airlines2 = "";
            string AirlineCode2 = "";
            string Airlines3 = "";
            string AirlineCode3 = "";
            string Airlines4 = "";
            string AirlineCode4 = "";
            string Airlines5 = "";
            string AirlineCode5 = "";

            string LocationFrom = "";
            string LocationTo = "";
            string OutboundDepartureTime = "";
            string OutboundArrivalTime = "";
            string InboundDepartureTime = "";
            string InboundArrivalTime = "";
            string OutboundFlightNumber = "";
            string InboundFlightNumber = "";
            string OutboundDuration = "";
            string InboundDuration = "";
            string FareClassInbound = "";
            string FareClassOutbound = "";
            string PricePerPassenger = "";
            string TotalPricePerPassenger = "";
            string totalAmount = "";
            string IncludesTax = "";
            string Provider = "";
            string CurrencyCode = "";
            string Amount = "";
            string ID = "";
            string AirportFrom = "";
            string AirportTo = "";
            string OutboundNoOfStops = "0";
            string InboundNoOfStops = "0";
            string OutboundLayOverInMin = "";
            string InboundLayOverInMin = "";

            string OutboundAirports = "";
            string OutboundAirport1 = "";
            string OutboundAirport2 = "";
            string OutboundAirport3 = "";
            string OutboundAirport4 = "";
            string OutboundAirport5 = "";
            string OutboundAirport6 = "";
            string OutboundAirport7 = "";
            string OutboundAirport8 = "";
            string OutboundAirport9 = "";
            string OutboundAirport10 = "";
            string OutboundAirport11 = "";
            string OutboundAirport12 = "";

            string OutboundFlightNo1 = "";
            string OutboundFlightNo2 = "";
            string OutboundFlightNo3 = "";
            string OutboundFlightNo4 = "";

            string InboundAirports = "";
            string InboundAirport1 = "";
            string InboundAirport2 = "";
            string InboundAirport3 = "";
            string InboundAirport4 = "";
            string InboundAirport5 = "";
            string InboundAirport6 = "";
            string InboundAirport7 = "";
            string InboundAirport8 = "";
            string InboundAirport9 = "";
            string InboundAirport10 = "";
            string InboundAirport11 = "";
            string InboundAirport12 = "";

            string InboundFlightNo1 = "";
            string InboundFlightNo2 = "";
            string InboundFlightNo3 = "";
            string InboundFlightNo4 = "";

            string LocationCode1 = "";
            string LocationCode2 = "";
            string LocationCode3 = "";
            string LocationCode4 = "";
            string LocationCode5 = "";

            string LocationName1 = "";
            string LocationName2 = "";
            string LocationName3 = "";
            string LocationName4 = "";
            string LocationName5 = "";

            #endregion var

            try
            {
                //xml string
                XmlTextReader reader = new XmlTextReader(new StringReader(results));
                //xml doc
                //XmlTextReader reader = new XmlTextReader(results);
                StringBuilder sb = new StringBuilder();

                string fieldname = "";
                bool isCarrier = false;
                bool isInboundInfo = false;
                bool isInboundAirport = false;
                bool isInboundFlightClass = false;
                bool isInboundFlightNos = false;
                bool isOutboundInfo = false;
                bool isOutboundAirport = false;
                bool isOutboundFlightClass = false;
                bool isOutboundFlightNos = false;
                bool isLocation = false;
                bool isLocationTo = false;

                while (reader.Read())
                {
                    if (reader.NodeType == XmlNodeType.Element)  //should be in order with the xml
                    {
                        //inboundinfo
                        if (isRoundTrip)
                        {
                            if (reader.Name == "inboundInfo")
                            {
                                isInboundInfo = true;
                            }

                            if (isInboundInfo && reader.Name == "layoverInMin")
                            {                                
                                fieldname = "InboundLayOverInMin";
                            }

                            if (isInboundInfo && reader.Name == "flightNumbers")
                            {
                                isInboundFlightNos = true;
                            }

                            if (isInboundInfo && isInboundFlightNos && reader.Name == "e")
                            {
                                fieldname = "InboundFlightNumber";
                            }

                            if (isInboundInfo && reader.Name == "durationInMin")
                            {
                                isInboundFlightNos = false;
                                fieldname = "InboundDuration";
                            }

                            if (isInboundInfo && reader.Name == "localDepartureTimeStr")
                            {
                                fieldname = "InboundDepartureTime";
                            }

                            if (isInboundInfo && reader.Name == "airports")
                            {
                                isInboundAirport = true;
                            }

                            if (isInboundInfo && isInboundAirport && reader.Name == "airports")
                            {
                                fieldname = "InboundAirports";
                            }                          

                            if (isInboundInfo && reader.Name == "numStops")
                            {
                                fieldname = "InboundNumStops";
                            }

                            if (isInboundInfo && reader.Name == "flightClasses")
                            {
                                isInboundFlightClass = true;
                            }

                            if (isInboundInfo && isInboundFlightClass && reader.Name == "fareClass")
                            {
                                fieldname = "FareClassInbound";
                            }


                            if (isInboundInfo && reader.Name == "localArrivalTimeStr")
                            {
                                fieldname = "InboundArrivalTime";
                            }

                        }
                        //endinbound

                        //location
                        if (reader.Name == "location")
                        {
                            isLocation = true;
                        }

                        if (isLocation && reader.Name == "code")
                        {
                            fieldname = "LocationCode";

                        }

                        if (isLocation && reader.Name == "name")
                        {
                            fieldname = "LocationName";

                        }
                        //endlocation

                        if (reader.Name == "carrier")
                        {
                            isLocation = false;
                            isCarrier = true;
                        }

                        if (isCarrier && reader.Name == "code")
                        {
                            fieldname = "airlineCode";
                        }

                        if (isCarrier && reader.Name == "name")
                        {
                            fieldname = "airlines";
                        }

                        //price
                        if (reader.Name == "amount")
                        {
                            isCarrier = false;
                            fieldname = "amount";
                        }

                        if (reader.Name == "totalAmount")
                        {
                            fieldname = "totalAmount";
                        }

                        if (reader.Name == "pricePerPassenger")
                        {
                            fieldname = "pricePerPassenger";
                        }

                        if (reader.Name == "currencyCode")
                        {
                            fieldname = "currencyCode";
                        }

                        if (reader.Name == "totalPricePerPassenger")
                        {
                            fieldname = "totalPricePerPassenger";
                        }

                        if (reader.Name == "includesTax")
                        {
                            fieldname = "includesTax";
                        }
                        //endprice


                        if (reader.Name == "providerId")
                        {
                            fieldname = "providerId";
                        }

                        //AirlineCode
                        if (reader.Name == "id")
                        {
                            fieldname = "ID";
                        }

                        if (reader.Name == "originCountryCode")
                        {
                            fieldname = "originCountryCode";
                        }

                        if (reader.Name == "bookingCode")
                        {
                            fieldname = "bookingCode";
                        }

                        if (reader.Name == "destinationCountryCode")
                        {
                            fieldname = "destinationCountryCode";
                        }

                        //outboundinfo
                        if (reader.Name == "outboundInfo")
                        {
                            isOutboundInfo = true;
                        }

                        if (isOutboundInfo && reader.Name == "layoverInMin")
                        {                            
                            fieldname = "OutboundLayOverInMin";
                        }

                        if (isOutboundInfo && reader.Name == "flightNumbers")
                        {
                            isOutboundFlightNos = true;
                        }

                        if (isOutboundInfo && isOutboundFlightNos && reader.Name == "e")
                        {
                            fieldname = "OutboundFlightNumber";
                        }

                        if (isOutboundInfo && reader.Name == "durationInMin")
                        {
                            isOutboundFlightNos = false;
                            fieldname = "OutboundDuration";
                        }

                        if (isOutboundInfo && reader.Name == "localDepartureTimeStr")
                        {
                            fieldname = "OutboundDepartureTime";
                        }

                        if (isOutboundInfo && reader.Name == "airports")
                        {
                            isOutboundAirport = true;
                        }

                        if (isOutboundInfo && isOutboundAirport && reader.Name == "airports")
                        {
                            fieldname = "OutboundAirports";
                        }

                        if (isOutboundInfo && isOutboundAirport && reader.Name == "arrivalTime")
                        {
                            isOutboundAirport = false;
                            fieldname = "outarrivalTime";
                        }

                        if (isOutboundInfo && reader.Name == "numStops")
                        {
                            fieldname = "OutboundNumStops";
                        }

                        if (isOutboundInfo && reader.Name == "flightClasses")
                        {
                            isOutboundFlightClass = true;
                        }

                        if (isOutboundInfo && isOutboundFlightClass && reader.Name == "fareClass")
                        {
                            fieldname = "FareClassOutbound";
                        }

                        if (isOutboundInfo && reader.Name == "localArrivalTimeStr")
                        {
                            fieldname = "OutboundArrivalTime";
                        }

                        //endoutbound                      

                    }

                    if (reader.NodeType == XmlNodeType.Text)
                    {
                        if (fieldname == "bookingCode")
                        {
                            BookingCode = reader.ReadString();
                            fieldname = "";
                        }

                        if (fieldname == "airlineCode")
                        {
                            if (AirlineCode == "")
                                AirlineCode = reader.ReadString();
                            else if (AirlineCode2 == "")
                                AirlineCode2 = reader.ReadString();
                            else if (AirlineCode3 == "")
                                AirlineCode3 = reader.ReadString();
                            else if (AirlineCode4 == "")
                                AirlineCode4 = reader.ReadString();
                            else
                                AirlineCode5 = reader.ReadString();

                            fieldname = "";
                        }

                        if (fieldname == "airlines")
                        {
                            if (Airlines == "")
                                Airlines = reader.ReadString();
                            else if (Airlines2 == "")
                                Airlines2 = reader.ReadString();
                            else if (Airlines3 == "")
                                Airlines3 = reader.ReadString();
                            else if (Airlines4 == "")
                                Airlines4 = reader.ReadString();
                            else
                                Airlines5 = reader.ReadString();

                            fieldname = "";
                        }

                        if (fieldname == "ID")
                        {
                            ID = reader.ReadString();
                            fieldname = "";
                        }

                        //inboundfields
                        if (fieldname == "InboundAirports")
                        {
                            if (InboundAirport1 == "")
                                InboundAirport1 = reader.ReadString();

                            else if (InboundAirport2 == "")
                                InboundAirport2 = reader.ReadString();

                            else if (InboundAirport3 == "")
                                InboundAirport3 = reader.ReadString();

                            else if (InboundAirport4 == "")
                                InboundAirport4 = reader.ReadString();

                            else if (InboundAirport5 == "")
                                InboundAirport5 = reader.ReadString();

                            else if (InboundAirport6 == "")
                                InboundAirport6 = reader.ReadString();

                            else if (InboundAirport7 == "")
                                InboundAirport7 = reader.ReadString();

                            else if (InboundAirport8 == "")
                                InboundAirport8 = reader.ReadString();

                            else if (InboundAirport9 == "")
                                InboundAirport9 = reader.ReadString();

                            else if (InboundAirport10 == "")
                                InboundAirport10 = reader.ReadString();

                            else if (InboundAirport11 == "")
                                InboundAirport11 = reader.ReadString();

                            else if (InboundAirport12 == "")
                                InboundAirport12 = reader.ReadString();

                            fieldname = "";
                        }

                        if (fieldname == "InboundDuration")
                        {          
                            InboundDuration = reader.ReadString();
                            fieldname = "";
                        }

                        if (fieldname == "FareClassInbound")
                        {
                            FareClassInbound = reader.ReadString();
                            fieldname = "";                            
                        }

                        if (fieldname == "InboundFlightNumber")
                        {
                            //InboundFlightNumber = InboundFlightNumber + "," + reader.ReadString();
                            if (InboundFlightNo1 == "")
                                InboundFlightNo1 = reader.ReadString();
                            else if (InboundFlightNo2 == "")
                                InboundFlightNo2 = reader.ReadString();
                            else if (InboundFlightNo3 == "")
                                InboundFlightNo4 = reader.ReadString();
                            else if (InboundFlightNo4 == "")
                                InboundFlightNo4 = reader.ReadString();

                            fieldname = "";
                            //isInboundFlightNos = false;
                        }

                        if (fieldname == "InboundLayOverInMin")
                        {
                            InboundLayOverInMin = reader.ReadString();
                            fieldname = "";
                        }

                        if (fieldname == "InboundDepartureTime")
                        {                            
                            InboundDepartureTime = reader.ReadString();
                            fieldname = "";
                        }

                        if (fieldname == "InboundNumStops")
                        {
                            InboundNoOfStops = reader.ReadString();
                            fieldname = "";                            
                        }

                        if (fieldname == "InboundArrivalTime")
                        {
                            InboundArrivalTime = reader.ReadString();
                            fieldname = "";
                            isInboundInfo = false;
                            isInboundAirport = false;
                            isInboundFlightClass = false;
                        }
                        //endinbound

                        //locationairportname
                        if (fieldname == "LocationCode")
                        {
                            if (LocationCode1 == "")
                                LocationCode1 = reader.ReadString();

                            if (LocationCode2 == "")
                                LocationCode2 = reader.ReadString();

                            if (LocationCode3 == "")
                                LocationCode3 = reader.ReadString();

                            if (LocationCode4 == "")
                                LocationCode4 = reader.ReadString();

                            if (LocationCode5 == "")
                                LocationCode5 = reader.ReadString();

                        }

                        if (fieldname == "LocationName")
                        {
                            if (LocationName1 == "")
                                LocationName1 = reader.ReadString();

                            if (LocationName2 == "")
                                LocationName2 = reader.ReadString();

                            if (LocationName3 == "")
                                LocationName3 = reader.ReadString();

                            if (LocationName4 == "")
                                LocationName4 = reader.ReadString();

                            if (LocationName5 == "")
                                LocationName5 = reader.ReadString();

                        }

                        //outboundfields
                        if (fieldname == "OutboundAirports")
                        {                           
                            if (OutboundAirport1 == "")
                                OutboundAirport1 = reader.ReadString();

                            else if (OutboundAirport2 == "")
                                OutboundAirport2 = reader.ReadString();

                            else if (OutboundAirport3 == "")
                                OutboundAirport3 = reader.ReadString();

                            else if (OutboundAirport4 == "")
                                OutboundAirport4 = reader.ReadString();

                            else if (OutboundAirport5 == "")
                                OutboundAirport5 = reader.ReadString();

                            else if (OutboundAirport6 == "")
                                OutboundAirport6 = reader.ReadString();

                            else if (OutboundAirport7 == "")
                                OutboundAirport7 = reader.ReadString();

                            else if (OutboundAirport8 == "")
                                OutboundAirport8 = reader.ReadString();

                            else if (OutboundAirport9 == "")
                                OutboundAirport9 = reader.ReadString();

                            else if (OutboundAirport10 == "")
                                OutboundAirport10 = reader.ReadString();

                            else if (OutboundAirport11 == "")
                                OutboundAirport11 = reader.ReadString();

                            else if (OutboundAirport12 == "")
                                OutboundAirport12 = reader.ReadString();

                        }

                        if (fieldname == "OutboundDuration")
                        {
                            OutboundDuration = reader.ReadString();
                            fieldname = "";
                        }

                        if (fieldname == "FareClassOutbound")
                        {
                            FareClassOutbound = reader.ReadString();
                            fieldname = "";
                            
                        }

                        if (fieldname == "OutboundFlightNumber")
                        {
                            //OutboundFlightNumber = OutboundFlightNumber + "," + reader.ReadString();

                            if (OutboundFlightNo1 == "")
                                OutboundFlightNo1 = reader.ReadString();
                            else if (OutboundFlightNo2 == "")
                                OutboundFlightNo2 = reader.ReadString();
                            else if (OutboundFlightNo3 == "")
                                OutboundFlightNo4 = reader.ReadString();
                            else if (OutboundFlightNo4 == "")
                                OutboundFlightNo4 = reader.ReadString();

                            fieldname = "";
                        }

                        if (fieldname == "OutboundLayOverInMin")
                        {
                            OutboundLayOverInMin = reader.ReadString();
                            fieldname = "";
                        }

                        if (fieldname == "OutboundDepartureTime")
                        {
                            OutboundDepartureTime = reader.ReadString();
                            fieldname = "";
                        }

                        if (fieldname == "OutboundNumStops")
                        {
                            OutboundNoOfStops = reader.ReadString();
                            fieldname = "";                            
                        }

                        if (fieldname == "OutboundArrivalTime")
                        {
                            OutboundArrivalTime = reader.ReadString();
                            fieldname = "";
                            isOutboundInfo = false;
                            isOutboundAirport = false;
                            isOutboundFlightClass = false;
                        }
                        //endoutbound

                        if (fieldname == "originCountryCode")
                        {
                            LocationFrom = reader.ReadString();
                            fieldname = "";
                        }

                        if (fieldname == "destinationCountryCode")
                        {
                            LocationTo = reader.ReadString();
                            fieldname = "";
                        }

                        if (fieldname == "amount")
                        {
                            Amount = reader.ReadString();
                            fieldname = "";
                        }

                        if (fieldname == "currencyCode")
                        {
                            CurrencyCode = reader.ReadString();
                            fieldname = "";
                        }

                        if (fieldname == "includesTax")
                        {
                            IncludesTax = reader.ReadString();
                            fieldname = "";
                        }

                        if (fieldname == "pricePerPassenger")
                        {
                            PricePerPassenger = reader.ReadString();
                            fieldname = "";
                        }

                        if (fieldname == "totalAmount")
                        {
                            totalAmount = reader.ReadString();
                            fieldname = "";
                        }

                        if (fieldname == "totalPricePerPassenger")
                        {
                            TotalPricePerPassenger = reader.ReadString();
                            fieldname = "";
                        }


                        if (fieldname == "providerId")
                        {
                            Provider = reader.ReadString();
                            fieldname = "";
                        }

                    }


                    if (reader.NodeType == XmlNodeType.EndElement && reader.Name == "itinerary")
                    {
                        //if (InboundNoOfStops == "0" && OutboundNoOfStops == "0")
                        //{
                        //dr = _dtflights.NewRow();

                        OutboundAirports = OutboundAirport1 + "," + OutboundAirport2 + "," + OutboundAirport3 + "," + OutboundAirport4
                                         + "," + OutboundAirport5 + "," + OutboundAirport6 + "," + OutboundAirport7 + "," + OutboundAirport8
                                         + "," + OutboundAirport9 + "," + OutboundAirport10 + "," + OutboundAirport11 + "," + OutboundAirport12;

                        InboundAirports = InboundAirport1 + "," + InboundAirport2 + "," + InboundAirport3 + "," + InboundAirport4
                                         + "," + InboundAirport5 + "," + InboundAirport6 + "," + InboundAirport7 + "," + InboundAirport8
                                         + "," + InboundAirport9 + "," + InboundAirport10 + "," + InboundAirport11 + "," + InboundAirport12;

                        OutboundFlightNumber = OutboundFlightNo1 + "," + OutboundFlightNo2 + "," + OutboundFlightNo3 + "," + OutboundFlightNo4;
                        InboundFlightNumber = InboundFlightNo1 + "," + InboundFlightNo2 + "," + InboundFlightNo3 + "," + InboundFlightNo4;

                        //dr["BookingCode"] = BookingCode;
                        wegoinfo.BookingCode = BookingCode;
                        wegoinfo.ViewId = Convert.ToInt64(viewid);

                        //dr["ID"] = ID;
                        wegoinfo.ID = ID;

                        //dr["Airlines"] = Airlines;

                        if (ID.Trim().Substring(0, 2) == AirlineCode)
                        {
                            wegoinfo.Airlines = Airlines;
                            wegoinfo.AirlineCode = AirlineCode;
                        }
                        else
                        {
                            string aircode = ID.Trim().Substring(0, 2);
                            wegoinfo.AirlineCode = aircode;

                            if (aircode == AirlineCode2)
                                wegoinfo.Airlines = Airlines2;
                            else if (aircode == AirlineCode3)
                                wegoinfo.Airlines = Airlines3;
                            else if (aircode == AirlineCode4)
                                wegoinfo.Airlines = Airlines4;
                            else
                                wegoinfo.Airlines = Airlines5;

                        }

                        //dr["LocationFrom"] = LocationFrom;
                        wegoinfo.LocationFrom = LocationFrom;

                        //dr["LocationTo"] = LocationTo;
                        wegoinfo.LocationTo = LocationTo;

                        //dr["AirportFrom"] = AirportFrom;
                        wegoinfo.AirportFrom = AirportFrom;

                        //dr["AirportTo"] = AirportTo;
                        wegoinfo.AirportTo = AirportTo;

                        //dr["OutboundDepartureTime"] = OutboundDepartureTime;
                        wegoinfo.OutboundDepartureTime = OutboundDepartureTime;

                        //dr["OutboundArrivalTime"] = OutboundArrivalTime;
                        wegoinfo.OutboundArrivalTime = OutboundArrivalTime;

                        //dr["InboundDepartureTime"] = InboundDepartureTime;
                        wegoinfo.InboundDepartureTime = InboundDepartureTime;

                        //dr["InboundArrivalTime"] = InboundArrivalTime;
                        wegoinfo.InboundArrivalTime = InboundArrivalTime;

                        //dr["OutboundFlightNumber"] = OutboundFlightNumber;
                        wegoinfo.OutboundFlightNumber = OutboundFlightNumber;

                        //dr["InboundFlightNumber"] = InboundFlightNumber;
                        wegoinfo.InboundFlightNumber = InboundFlightNumber;

                        //dr["OutboundAirports"] = OutboundAirports;
                        wegoinfo.OutboundAirports = OutboundAirports;

                        //dr["InboundAirports"] = InboundAirports;
                        wegoinfo.InboundAirports = InboundAirports;

                        //dr["OutboundDuration"] = OutboundDuration;
                        wegoinfo.OutboundDuration = OutboundDuration;

                        //dr["InboundDuration"] = InboundDuration;
                        wegoinfo.InboundDuration = InboundDuration;

                        //dr["FareClassInbound"] = FareClassInbound;
                        wegoinfo.FareClassInbound = FareClassInbound;

                        //dr["FareClassOutbound"] = FareClassOutbound;
                        wegoinfo.FareClassOutbound = FareClassOutbound;

                        if (CurrencyCode != "SGD")
                        {
                            double priceperpassenger = GetExchangeRates(CurrencyCode, double.Parse(PricePerPassenger));
                            //double priceperpassenger = double.Parse(PricePerPassenger);

                            //dr["PricePerPassenger"] = priceperpassenger;

                            wegoinfo.PricePerPassenger = float.Parse(priceperpassenger.ToString());

                            double totalpriceperpassenger;
                            if (TotalPricePerPassenger == "0.00" || TotalPricePerPassenger == "")
                            {
                                totalpriceperpassenger = GetExchangeRates(CurrencyCode, double.Parse(PricePerPassenger));
                                //totalpriceperpassenger = double.Parse(PricePerPassenger);

                                //dr["totalPricePerPassenger"] = totalpriceperpassenger;
                            }
                            else
                            {
                                totalpriceperpassenger = GetExchangeRates(CurrencyCode, double.Parse(TotalPricePerPassenger));
                                //totalpriceperpassenger = double.Parse(TotalPricePerPassenger);

                                //dr["totalPricePerPassenger"] = totalpriceperpassenger;
                            }

                            wegoinfo.TotalPricePerPassenger = float.Parse(totalpriceperpassenger.ToString());

                            double dtotalAmount = 0;
                            if (totalAmount != "0.00" && totalAmount != "")
                            {
                                dtotalAmount = GetExchangeRates(CurrencyCode, double.Parse(totalAmount));
                                //dtotalAmount = double.Parse(totalAmount);
                            }

                            //dr["totalAmount"] = dtotalAmount;
                            wegoinfo.TotalAmount = float.Parse(dtotalAmount.ToString());

                            double dAmount = 0;
                            if (Amount != "0.00" && Amount != "")
                            {
                                dAmount = GetExchangeRates(CurrencyCode, double.Parse(Amount));
                                //dAmount = double.Parse(Amount);
                            }

                            //dr["Amount"] = dAmount;
                            wegoinfo.Amount = float.Parse(dAmount.ToString());

                            //dr["CurrencyCode"] = "SGD";
                            wegoinfo.CurrencyCode = "SGD";
                        }
                        else
                        {
                            //dr["PricePerPassenger"] = PricePerPassenger;
                            wegoinfo.PricePerPassenger = float.Parse(PricePerPassenger);

                            if (TotalPricePerPassenger == "0.00" || TotalPricePerPassenger == "")
                            {
                                //dr["totalPricePerPassenger"] = PricePerPassenger;
                                wegoinfo.TotalPricePerPassenger = float.Parse(PricePerPassenger);
                            }
                            else
                            {
                                //dr["totalPricePerPassenger"] = TotalPricePerPassenger;
                                wegoinfo.TotalPricePerPassenger = float.Parse(TotalPricePerPassenger);
                            }

                            double dtotalAmount = 0;
                            if (totalAmount != "0.00" && totalAmount != "")
                            {
                                dtotalAmount = double.Parse(totalAmount);
                            }
                            //dr["totalAmount"] = dtotalAmount;
                            wegoinfo.TotalAmount = float.Parse(dtotalAmount.ToString());

                            double dAmount = 0;
                            if (Amount != "0.00" && Amount != "")
                            {
                                dAmount = double.Parse(Amount);
                            }
                            //dr["Amount"] = dAmount;
                            wegoinfo.Amount = float.Parse(dAmount.ToString());

                            //dr["CurrencyCode"] = CurrencyCode;
                            wegoinfo.CurrencyCode = CurrencyCode;
                        }

                        //dr["IncludesTax"] = IncludesTax;
                        wegoinfo.IncludesTax = bool.Parse(IncludesTax);

                        //dr["Provider"] = Provider;
                        wegoinfo.Provider = Provider;

                        //dr["InboundNoOfStops"] = InboundNoOfStops;
                        wegoinfo.InboundNoOfStops = InboundNoOfStops;

                        //dr["OutboundNoOfStops"] = OutboundNoOfStops;
                        wegoinfo.OutboundNoOfStops = OutboundNoOfStops;

                        //dr["OutboundLayOverInMin"] = OutboundLayOverInMin;
                        wegoinfo.OutboundLayOverInMin = OutboundLayOverInMin;

                        //dr["InboundLayOverInMin"] = InboundLayOverInMin;
                        wegoinfo.InboundLayOverInMin = InboundLayOverInMin;

                        wegoinfo.OutboundConnectingDetails = "";
                        wegoinfo.InboundConnectingDetails = "";

                        //if (InboundNoOfStops != "0" || OutboundNoOfStops != "0")
                        //{
                        //    DataTable dtDetails = new DataTable();

                        //    dtDetails = GetFlightDetails(instanceId, ID, outbounddate, inbounddate);

                        //    if (dtDetails.Rows.Count != 0)
                        //    {
                        //        string outboundconndetails = "";
                        //        string inboundconndetails = "";

                        //        foreach (DataRow rowdtl in dtDetails.Rows)
                        //        {
                        //            if (rowdtl["OutboundflightNumber"] != "")
                        //            {
                        //                outboundconndetails = outboundconndetails + "|" + rowdtl["OutboundflightNumber"].ToString() + ", " +
                        //                    rowdtl["OutbounddepartureDateTime"].ToString() + ", " +
                        //                    rowdtl["OutboundarrivalDateTime"].ToString() + ", " +
                        //                    rowdtl["OutbounddurationInMin"].ToString() + ", " +
                        //                    rowdtl["OutboundUTCLocalDepartureTimeVariation"].ToString() + ", " +
                        //                    rowdtl["OutboundUTCLocalArrivalTimeVariation"].ToString();
                        //            }

                        //            if (rowdtl["InboundflightNumber"] != "")
                        //            {
                        //                inboundconndetails = inboundconndetails + "|" + rowdtl["InboundflightNumber"].ToString() + ", " +
                        //                    rowdtl["InbounddepartureDateTime"].ToString() + ", " +
                        //                    rowdtl["InboundarrivalDateTime"].ToString() + ", " +
                        //                    rowdtl["InbounddurationInMin"].ToString() + ", " +
                        //                    rowdtl["InboundUTCLocalDepartureTimeVariation"].ToString() + ", " +
                        //                    rowdtl["InboundUTCLocalArrivalTimeVariation"].ToString();
                        //            }
                        //        }

                        //        //dr["OutboundConnectingDetails"] = outboundconndetails;
                        //        //dr["InboundConnectingDetails"] = inboundconndetails;

                        //        wegoinfo.OutboundConnectingDetails = outboundconndetails;
                        //        wegoinfo.InboundConnectingDetails = inboundconndetails;

                        //    }

                        //    dtDetails.Clear();
                        //}


                        //_dtflights.Rows.Add(dr);
                        wegodb.Insert(wegoinfo);

                        Airlines = "";
                        Airlines2 = "";
                        Airlines3 = "";
                        Airlines4 = "";
                        Airlines5 = "";

                        AirlineCode = "";
                        AirlineCode2 = "";
                        AirlineCode3 = "";
                        AirlineCode4 = "";
                        AirlineCode5 = "";

                        //add to Airloc table
                        int loccount = 0;

                        if (LocationCode5 != "")
                            loccount = 5;
                        else if (LocationCode4 != "")
                            loccount = 4;
                        else if (LocationCode3 != "")
                            loccount = 3;
                        else
                            loccount = 2;

                        for (int i = 1; i <= loccount; i++)
                        {
                            //drairloc = _dtairloc.NewRow();
                            //drairloc["BookingCode"] = BookingCode;
                            //drairloc["ID"] = ID;
                            string dtlLocationCode = "";
                            string dtlLocationName = "";

                            if (i == 1)
                            {
                                //drairloc["LocationCode"] = LocationCode1;
                                //drairloc["LocationName"] = LocationName1;
                                dtlLocationCode = LocationCode1;
                                dtlLocationName = LocationName1;
                            }
                            if (i == 2)
                            {
                                //drairloc["LocationCode"] = LocationCode2;
                                //drairloc["LocationName"] = LocationName2;
                                dtlLocationCode = LocationCode2;
                                dtlLocationName = LocationName2;
                            }
                            if (i == 3)
                            {
                                //drairloc["LocationCode"] = LocationCode3;
                                //drairloc["LocationName"] = LocationName3;
                                dtlLocationCode = LocationCode3;
                                dtlLocationName = LocationName3;
                            }
                            if (i == 4)
                            {
                                //drairloc["LocationCode"] = LocationCode4;
                                //drairloc["LocationName"] = LocationName4;
                                dtlLocationCode = LocationCode4;
                                dtlLocationName = LocationName4;
                            }
                            if (i == 5)
                            {
                                //drairloc["LocationCode"] = LocationCode5;
                                //drairloc["LocationName"] = LocationName5;
                                dtlLocationCode = LocationCode5;
                                dtlLocationName = LocationName5;
                            }

                            wegodb.InsertToAirportLocation(Convert.ToInt64(viewid), BookingCode, ID, dtlLocationCode, dtlLocationName);
                            //_dtairloc.Rows.Add(drairloc);

                        }


                        // }

                        InboundNoOfStops = "0";
                        OutboundNoOfStops = "0";

                        LocationCode1 = "";
                        LocationCode2 = "";
                        LocationCode3 = "";
                        LocationCode4 = "";
                        LocationCode5 = "";
                        LocationName1 = "";
                        LocationName2 = "";
                        LocationName3 = "";
                        LocationName4 = "";
                        LocationName5 = "";

                        OutboundAirports = "";
                        OutboundAirport1 = "";
                        OutboundAirport2 = "";
                        OutboundAirport3 = "";
                        OutboundAirport4 = "";
                        OutboundAirport5 = "";
                        OutboundAirport6 = "";
                        OutboundAirport7 = "";
                        OutboundAirport8 = "";
                        OutboundAirport9 = "";
                        OutboundAirport10 = "";
                        OutboundAirport11 = "";
                        OutboundAirport12 = "";

                        OutboundFlightNo1 = "";
                        OutboundFlightNo2 = "";
                        OutboundFlightNo3 = "";
                        OutboundFlightNo4 = "";

                        InboundAirports = "";
                        InboundAirport1 = "";
                        InboundAirport2 = "";
                        InboundAirport3 = "";
                        InboundAirport4 = "";
                        InboundAirport5 = "";
                        InboundAirport6 = "";
                        InboundAirport7 = "";
                        InboundAirport8 = "";
                        InboundAirport9 = "";
                        InboundAirport10 = "";
                        InboundAirport11 = "";
                        InboundAirport12 = "";

                        InboundFlightNo1 = "";
                        InboundFlightNo2 = "";
                        InboundFlightNo3 = "";
                        InboundFlightNo4 = "";

                        InboundFlightNumber = "";
                        OutboundFlightNumber = "";
                    }
                }

                reader.Close();
                isDone = true;

            }
            catch (Exception Ex)
            {
                isDone = false;
                Ex.ToString();
                CreateExceptionLog(Ex, "FlightsResultsXMLtoTable");
            }

            //_dsFlights.Tables.Add(_dtflights);
            //_dsFlights.Tables.Add(_dtairloc);

            //return _dsFlights;

            return isDone;
        }

        public DataTable GetFlightDetails(string instanceid, string itineraryid, string outbounddate, string inbounddate)
        {
            string _flightdetails = "";
            DataTable dtDetails = new DataTable();

            try
            {
                //HttpWebRequest req = (HttpWebRequest)WebRequest.Create(@"http://www.wego.com/api/flights/details.html? " + @"&apiKey=" + API_KEY + "&format=xml&instanceId=" + instanceid + "&itineraryId=" + itineraryid +
                //    "&outboundDate=" + outbounddate + "&inboundDate=" + inbounddate);
                ////http://www.wego.com/api/flights/details.html?instanceId=c90a013e708e5ffcc526dd81ac42acf5f6040739&itineraryId=CX712[SIN-BKK]|CX713[BKK-SIN]&format=json&outboundDate=2010-06-23&inboundDate=2010-06-26&apiKey=testApiKey 

                //req.Timeout = 3600 * 1000;
                //req.Method = "GET";
                //req.Referer = "http://www.comparexpress.com";
                //HttpWebResponse webResponse = (HttpWebResponse)req.GetResponse();
                //Stream stream = webResponse.GetResponseStream();
                //StreamReader answer = new StreamReader(stream);
                //_flightdetails = answer.ReadToEnd();

                //answer.Close();
                //webResponse.Close();

                _flightdetails = GetResponse("http://www.wego.com/api/flights/details.html?apiKey=" + API_KEY + "&format=xml&instanceId=" + instanceid + "&itineraryId=" + itineraryid + "&outboundDate=" + outbounddate + "&inboundDate=" + inbounddate);

                dtDetails = FlightsDetailsTable();

                DataRow drDetails;

                string OutboundflightNumber = "";
                string OutbounddepartureStation = "";
                string OutboundpassengerSTD = "";
                string OutboundUTCLocalDepartureTimeVariation = "";
                string OutboundpassengerDepartureTerminal = "";
                string OutboundarrivalStation = "";
                string OutboundSTA = "";
                string OutboundpassengerSTA = "";
                string OutboundUTCLocalArrivalTimeVariation = "";
                string OutboundaircraftType = "";
                string OutboundoperatorCode = "";
                string OutbounddurationInMin = "";
                string OutbounddepartureDateTime = "";
                string OutboundarrivalDateTime = "";
                string InboundflightNumber = "";
                string InbounddepartureStation = "";
                string InboundpassengerSTD = "";
                string InboundUTCLocalDepartureTimeVariation = "";
                string InboundpassengerDepartureTerminal = "";
                string InboundarrivalStation = "";
                string InboundSTA = "";
                string InboundpassengerSTA = "";
                string InboundUTCLocalArrivalTimeVariation = "";
                string InboundaircraftType = "";
                string InboundoperatorCode = "";
                string InbounddurationInMin = "";
                string InbounddepartureDateTime = "";
                string InboundarrivalDateTime = "";

                try
                {
                    XmlTextReader reader = new XmlTextReader(new StringReader(_flightdetails));
                    StringBuilder sb = new StringBuilder();

                    string fieldname = "";
                    bool isOutbound = false;
                    bool isInbound = false;
                    bool isOutboundFlightNo = false;
                    bool isInboundFlightNo = false;

                    while (reader.Read())
                    {

                        if (reader.NodeType == XmlNodeType.Element)
                        {
                            if (reader.Name == "outboundSegments")
                            {
                                isOutbound = true;
                            }

                            if (reader.Name == "flightNumber" && isOutbound)
                            {
                                isOutboundFlightNo = true;
                            }

                            if (reader.Name == "designator" && isOutbound && isOutboundFlightNo)
                            {
                                fieldname = "OutboundflightNumber";
                            }

                            if (reader.Name == "number" && isOutbound && isOutboundFlightNo)
                            {
                                fieldname = "OutboundflightNumber";
                            }

                            if (reader.Name == "operatingAirlineFlightNumber" && isOutbound)
                            {
                                isOutboundFlightNo = false;
                            }

                            if (reader.Name == "departureStation" && isOutbound)
                            {
                                fieldname = "OutbounddepartureStation";
                            }

                            if (reader.Name == "passengerSTD" && isOutbound)
                            {
                                fieldname = "OutboundpassengerSTD";
                            }

                            if (reader.Name == "UTCLocalDepartureTimeVariation" && isOutbound)
                            {
                                fieldname = "OutboundUTCLocalDepartureTimeVariation";
                            }

                            if (reader.Name == "passengerDepartureTerminal" && isOutbound)
                            {
                                fieldname = "passengerDepartureTerminal";
                            }

                            if (reader.Name == "arrivalStation" && isOutbound)
                            {
                                fieldname = "OutboundarrivalStation";
                            }

                            if (reader.Name == "STA" && isOutbound)
                            {
                                fieldname = "OutboundSTA";
                            }

                            if (reader.Name == "passengerSTA" && isOutbound)
                            {
                                fieldname = "OutboundpassengerSTA";
                            }

                            if (reader.Name == "UTCLocalArrivalTimeVariation" && isOutbound)
                            {
                                fieldname = "OutboundUTCLocalArrivalTimeVariation";
                            }

                            if (reader.Name == "aircraftType" && isOutbound)
                            {
                                fieldname = "OutboundaircraftType";
                            }

                            if (reader.Name == "operatorCode" && isOutbound)
                            {
                                fieldname = "OutboundoperatorCode";
                            }

                            if (reader.Name == "durationInMin" && isOutbound)
                            {
                                fieldname = "OutbounddurationInMin";
                            }

                            if (reader.Name == "departureDateTime" && isOutbound)
                            {
                                fieldname = "OutbounddepartureDateTime";
                            }

                            if (reader.Name == "arrivalDateTime" && isOutbound)
                            {
                                fieldname = "OutboundarrivalDateTime";

                            }

                            if (reader.Name == "inboundSegments")
                            {
                                isOutbound = false;
                                isInbound = true;
                            }

                            if (reader.Name == "flightNumber" && isInbound)
                            {
                                isInboundFlightNo = true;
                            }

                            if (reader.Name == "designator" && isInbound && isInboundFlightNo)
                            {
                                fieldname = "InboundflightNumber";
                            }

                            if (reader.Name == "number" && isInbound && isInboundFlightNo)
                            {
                                fieldname = "InboundflightNumber";
                            }

                            if (reader.Name == "operatingAirlineFlightNumber" && isInbound)
                            {
                                isInboundFlightNo = false;
                            }

                            if (reader.Name == "departureStation" && isInbound)
                            {
                                fieldname = "InbounddepartureStation";
                            }

                            if (reader.Name == "passengerSTD" && isInbound)
                            {
                                fieldname = "InboundpassengerSTD";
                            }

                            if (reader.Name == "UTCLocalDepartureTimeVariation" && isInbound)
                            {
                                fieldname = "InboundUTCLocalDepartureTimeVariation";
                            }

                            if (reader.Name == "passengerDepartureTerminal" && isInbound)
                            {
                                fieldname = "InboundpassengerDepartureTerminal";
                            }

                            if (reader.Name == "arrivalStation" && isInbound)
                            {
                                fieldname = "InboundarrivalStation";
                            }

                            if (reader.Name == "STA" && isInbound)
                            {
                                fieldname = "InboundSTA";
                            }

                            if (reader.Name == "passengerSTA" && isInbound)
                            {
                                fieldname = "InboundpassengerSTA";
                            }

                            if (reader.Name == "UTCLocalArrivalTimeVariation" && isInbound)
                            {
                                fieldname = "InboundUTCLocalArrivalTimeVariation";
                            }

                            if (reader.Name == "aircraftType" && isInbound)
                            {
                                fieldname = "InboundaircraftType";
                            }

                            if (reader.Name == "operatorCode" && isInbound)
                            {
                                fieldname = "InboundoperatorCode";
                            }

                            if (reader.Name == "durationInMin" && isInbound)
                            {
                                fieldname = "InbounddurationInMin";
                            }

                            if (reader.Name == "departureDateTime" && isInbound)
                            {
                                fieldname = "InbounddepartureDateTime";
                            }

                            if (reader.Name == "arrivalDateTime" && isInbound)
                            {
                                fieldname = "InboundarrivalDateTime";

                            }
                        }

                        if (reader.NodeType == XmlNodeType.Text)
                        {
                            if (fieldname == "OutboundflightNumber" && isOutbound)
                            {
                                OutboundflightNumber = OutboundflightNumber + reader.ReadString();
                                fieldname = "";
                            }

                            if (fieldname == "OutbounddepartureStation" && isOutbound)
                            {
                                OutbounddepartureStation = reader.ReadString();
                                fieldname = "";
                            }

                            if (fieldname == "OutboundpassengerSTD" && isOutbound)
                            {
                                OutboundpassengerSTD = reader.ReadString();
                                fieldname = "";
                            }

                            if (fieldname == "OutboundUTCLocalDepartureTimeVariation" && isOutbound)
                            {
                                OutboundUTCLocalDepartureTimeVariation = reader.ReadString();
                                fieldname = "";
                            }

                            if (fieldname == "OutboundpassengerDepartureTerminal" && isOutbound)
                            {
                                OutboundpassengerDepartureTerminal = reader.ReadString();
                                fieldname = "";
                            }

                            if (fieldname == "OutboundarrivalStation" && isOutbound)
                            {
                                OutboundarrivalStation = reader.ReadString();
                                fieldname = "";
                            }

                            if (fieldname == "OutboundSTA" && isOutbound)
                            {
                                OutboundSTA = reader.ReadString();
                                fieldname = "";
                            }

                            if (fieldname == "OutboundpassengerSTA" && isOutbound)
                            {
                                OutboundpassengerSTA = reader.ReadString();
                                fieldname = "";
                            }

                            if (fieldname == "OutboundUTCLocalArrivalTimeVariation" && isOutbound)
                            {
                                OutboundUTCLocalArrivalTimeVariation = reader.ReadString();
                                fieldname = "";
                            }

                            if (fieldname == "OutboundaircraftType" && isOutbound)
                            {
                                OutboundaircraftType = reader.ReadString();
                                fieldname = "";
                            }

                            if (fieldname == "OutboundoperatorCode" && isOutbound)
                            {
                                OutboundoperatorCode = reader.ReadString();
                                fieldname = "";
                            }

                            if (fieldname == "OutbounddurationInMin" && isOutbound)
                            {
                                OutbounddurationInMin = reader.ReadString();
                                fieldname = "";
                            }

                            if (fieldname == "OutbounddepartureDateTime" && isOutbound)
                            {
                                OutbounddepartureDateTime = reader.ReadString();
                                fieldname = "";
                            }

                            if (fieldname == "OutboundarrivalDateTime" && isOutbound)
                            {
                                OutboundarrivalDateTime = reader.ReadString();
                                fieldname = "";
                                //isOutbound = false;
                            }

                            if (fieldname == "InboundflightNumber" && isInbound)
                            {
                                InboundflightNumber = InboundflightNumber + reader.ReadString();
                                fieldname = "";
                            }

                            if (fieldname == "InbounddepartureStation" && isInbound)
                            {
                                InbounddepartureStation = reader.ReadString();
                                fieldname = "";
                            }

                            if (fieldname == "InboundpassengerSTD" && isInbound)
                            {
                                InboundpassengerSTD = reader.ReadString();
                                fieldname = "";
                            }

                            if (fieldname == "InboundUTCLocalDepartureTimeVariation" && isInbound)
                            {
                                InboundUTCLocalDepartureTimeVariation = reader.ReadString();
                                fieldname = "";
                            }

                            if (fieldname == "InboundpassengerDepartureTerminal" && isInbound)
                            {
                                InboundpassengerDepartureTerminal = reader.ReadString();
                                fieldname = "";
                            }

                            if (fieldname == "InboundarrivalStation" && isInbound)
                            {
                                InboundarrivalStation = reader.ReadString();
                                fieldname = "";
                            }

                            if (fieldname == "InboundSTA" && isInbound)
                            {
                                InboundSTA = reader.ReadString();
                                fieldname = "";
                            }

                            if (fieldname == "InboundpassengerSTA" && isInbound)
                            {
                                InboundpassengerSTA = reader.ReadString();
                                fieldname = "";
                            }

                            if (fieldname == "InboundUTCLocalArrivalTimeVariation" && isInbound)
                            {
                                InboundUTCLocalArrivalTimeVariation = reader.ReadString();
                                fieldname = "";
                            }

                            if (fieldname == "InboundaircraftType" && isInbound)
                            {
                                InboundaircraftType = reader.ReadString();
                                fieldname = "";
                            }

                            if (fieldname == "InboundoperatorCode" && isInbound)
                            {
                                InboundoperatorCode = reader.ReadString();
                                fieldname = "";
                            }

                            if (fieldname == "InbounddurationInMin" && isInbound)
                            {
                                InbounddurationInMin = reader.ReadString();
                                fieldname = "";
                            }

                            if (fieldname == "InbounddepartureDateTime" && isInbound)
                            {
                                InbounddepartureDateTime = reader.ReadString();
                                fieldname = "";
                            }

                            if (fieldname == "InboundarrivalDateTime" && isInbound)
                            {
                                InboundarrivalDateTime = reader.ReadString();
                                fieldname = "";
                                //isInbound = false;
                            }

                        }

                        if (reader.NodeType == XmlNodeType.EndElement && reader.Name == "segment")
                        {
                            drDetails = dtDetails.NewRow();

                            drDetails["OutboundflightNumber"] = OutboundflightNumber;
                            drDetails["OutbounddepartureStation"] = OutbounddepartureStation;
                            drDetails["OutboundpassengerSTD"] = OutboundpassengerSTD;
                            drDetails["OutboundUTCLocalDepartureTimeVariation"] = OutboundUTCLocalDepartureTimeVariation;
                            drDetails["OutboundpassengerDepartureTerminal"] = OutboundpassengerDepartureTerminal;
                            drDetails["OutboundarrivalStation"] = OutboundarrivalStation;
                            drDetails["OutboundSTA"] = OutboundSTA;
                            drDetails["OutboundpassengerSTA"] = OutboundpassengerSTA;
                            drDetails["OutboundUTCLocalArrivalTimeVariation"] = OutboundUTCLocalArrivalTimeVariation;
                            drDetails["OutboundaircraftType"] = OutboundaircraftType;
                            drDetails["OutboundoperatorCode"] = OutboundoperatorCode;
                            drDetails["OutbounddurationInMin"] = OutbounddurationInMin;
                            drDetails["OutbounddepartureDateTime"] = OutbounddepartureDateTime;
                            drDetails["OutboundarrivalDateTime"] = OutboundarrivalDateTime;
                            drDetails["InboundflightNumber"] = InboundflightNumber;
                            drDetails["InbounddepartureStation"] = InbounddepartureStation;
                            drDetails["InboundpassengerSTD"] = InboundpassengerSTD;
                            drDetails["InboundUTCLocalDepartureTimeVariation"] = InboundUTCLocalDepartureTimeVariation;
                            drDetails["InboundpassengerDepartureTerminal"] = InboundpassengerDepartureTerminal;
                            drDetails["InboundarrivalStation"] = InboundarrivalStation;
                            drDetails["InboundSTA"] = InboundSTA;
                            drDetails["InboundpassengerSTA"] = InboundpassengerSTA;
                            drDetails["InboundUTCLocalArrivalTimeVariation"] = InboundUTCLocalArrivalTimeVariation;
                            drDetails["InboundaircraftType"] = InboundaircraftType;
                            drDetails["InboundoperatorCode"] = InboundoperatorCode;
                            drDetails["InbounddurationInMin"] = InbounddurationInMin;
                            drDetails["InbounddepartureDateTime"] = InbounddepartureDateTime;
                            drDetails["InboundarrivalDateTime"] = InboundarrivalDateTime;

                            dtDetails.Rows.Add(drDetails);

                            OutboundflightNumber = "";
                            OutbounddepartureStation = "";
                            OutboundpassengerSTD = "";
                            OutboundUTCLocalDepartureTimeVariation = "";
                            OutboundpassengerDepartureTerminal = "";
                            OutboundarrivalStation = "";
                            OutboundSTA = "";
                            OutboundpassengerSTA = "";
                            OutboundUTCLocalArrivalTimeVariation = "";
                            OutboundaircraftType = "";
                            OutboundoperatorCode = "";
                            OutbounddurationInMin = "";
                            OutbounddepartureDateTime = "";
                            OutboundarrivalDateTime = "";
                            InboundflightNumber = "";
                            InbounddepartureStation = "";
                            InboundpassengerSTD = "";
                            InboundUTCLocalDepartureTimeVariation = "";
                            InboundpassengerDepartureTerminal = "";
                            InboundarrivalStation = "";
                            InboundSTA = "";
                            InboundpassengerSTA = "";
                            InboundUTCLocalArrivalTimeVariation = "";
                            InboundaircraftType = "";
                            InboundoperatorCode = "";
                            InbounddurationInMin = "";
                            InbounddepartureDateTime = "";
                            InboundarrivalDateTime = "";
                        }
                    }

                    reader.Close();


                }
                catch (XmlException xmlEx)
                {
                    xmlEx.ToString();
                    CreateExceptionLog(xmlEx, "GetFlightDetailsReadXML(string instanceId)");
                }
            }
            catch (WebException Wex)
            {
                CreateExceptionLog(Wex, "DataTable GetFlightDetails(string instanceid, string itineraryid, string outbounddate, string inbounddate)");
            }
            catch (ThreadAbortException Tex)
            {
                //do nothing
            }
            catch (Exception Ex)
            {
                CreateExceptionLog(Ex, "DataTable GetFlightDetails(string instanceid, string itineraryid, string outbounddate, string inbounddate)");
            }

            return dtDetails;
        }

        private DataTable FlightsTable()
        {
            DataTable dtWego = new DataTable();

            dtWego.Columns.Add("BookingCode", System.Type.GetType("System.String"));
            dtWego.Columns.Add("ID", System.Type.GetType("System.String"));
            dtWego.Columns.Add("Airlines", System.Type.GetType("System.String"));
            dtWego.Columns.Add("AirlineCode", System.Type.GetType("System.String"));
            dtWego.Columns.Add("LocationFrom", System.Type.GetType("System.String"));
            dtWego.Columns.Add("LocationTo", System.Type.GetType("System.String"));
            dtWego.Columns.Add("AirportFrom", System.Type.GetType("System.String"));
            dtWego.Columns.Add("AirportTo", System.Type.GetType("System.String"));
            dtWego.Columns.Add("OutboundDepartureTime", System.Type.GetType("System.String"));
            dtWego.Columns.Add("OutboundArrivalTime", System.Type.GetType("System.String"));
            dtWego.Columns.Add("InboundDepartureTime", System.Type.GetType("System.String"));
            dtWego.Columns.Add("InboundArrivalTime", System.Type.GetType("System.String"));
            dtWego.Columns.Add("OutboundFlightNumber", System.Type.GetType("System.String"));
            dtWego.Columns.Add("InboundFlightNumber", System.Type.GetType("System.String"));
            dtWego.Columns.Add("OutboundAirports", System.Type.GetType("System.String"));
            dtWego.Columns.Add("InboundAirports", System.Type.GetType("System.String"));
            dtWego.Columns.Add("OutboundDuration", System.Type.GetType("System.String"));
            dtWego.Columns.Add("InboundDuration", System.Type.GetType("System.String"));
            dtWego.Columns.Add("FareClassInbound", System.Type.GetType("System.String"));
            dtWego.Columns.Add("FareClassOutbound", System.Type.GetType("System.String"));
            dtWego.Columns.Add("Amount", System.Type.GetType("System.Double"));
            dtWego.Columns.Add("PricePerPassenger", System.Type.GetType("System.Double"));
            dtWego.Columns.Add("totalAmount", System.Type.GetType("System.Double"));
            dtWego.Columns.Add("totalPricePerPassenger", System.Type.GetType("System.Double"));
            dtWego.Columns.Add("CurrencyCode", System.Type.GetType("System.String"));
            dtWego.Columns.Add("IncludesTax", System.Type.GetType("System.String"));
            dtWego.Columns.Add("Provider", System.Type.GetType("System.String"));
            dtWego.Columns.Add("OutboundNoOfStops", System.Type.GetType("System.String"));
            dtWego.Columns.Add("InboundNoOfStops", System.Type.GetType("System.String"));
            dtWego.Columns.Add("OutboundLayOverInMin", System.Type.GetType("System.String"));
            dtWego.Columns.Add("InboundLayOverInMin", System.Type.GetType("System.String"));
            dtWego.Columns.Add("OutboundConnectingDetails", System.Type.GetType("System.String"));
            dtWego.Columns.Add("InboundConnectingDetails", System.Type.GetType("System.String"));

            return dtWego;
        }

        private DataTable AirportLocationTable()
        {

            DataTable dtAirLoc = new DataTable();

            dtAirLoc.Columns.Add("BookingCode", System.Type.GetType("System.String"));
            dtAirLoc.Columns.Add("ID", System.Type.GetType("System.String"));
            dtAirLoc.Columns.Add("LocationCode", System.Type.GetType("System.String"));
            dtAirLoc.Columns.Add("LocationName", System.Type.GetType("System.String"));

            return dtAirLoc;
        }

        private DataTable FlightsDetailsTable()
        {
            DataTable dtWegoDetails = new DataTable();

            dtWegoDetails.Columns.Add("OutboundflightNumber", System.Type.GetType("System.String"));
            dtWegoDetails.Columns.Add("OutbounddepartureStation", System.Type.GetType("System.String"));
            dtWegoDetails.Columns.Add("OutboundpassengerSTD", System.Type.GetType("System.String"));
            dtWegoDetails.Columns.Add("OutboundUTCLocalDepartureTimeVariation", System.Type.GetType("System.String"));
            dtWegoDetails.Columns.Add("OutboundpassengerDepartureTerminal", System.Type.GetType("System.String"));
            dtWegoDetails.Columns.Add("OutboundarrivalStation", System.Type.GetType("System.String"));
            dtWegoDetails.Columns.Add("OutboundSTA", System.Type.GetType("System.String"));
            dtWegoDetails.Columns.Add("OutboundpassengerSTA", System.Type.GetType("System.String"));
            dtWegoDetails.Columns.Add("OutboundUTCLocalArrivalTimeVariation", System.Type.GetType("System.String"));
            dtWegoDetails.Columns.Add("OutboundaircraftType", System.Type.GetType("System.String"));
            dtWegoDetails.Columns.Add("OutboundoperatorCode", System.Type.GetType("System.String"));
            dtWegoDetails.Columns.Add("OutbounddurationInMin", System.Type.GetType("System.String"));
            dtWegoDetails.Columns.Add("OutbounddepartureDateTime", System.Type.GetType("System.String"));
            dtWegoDetails.Columns.Add("OutboundarrivalDateTime", System.Type.GetType("System.String"));

            dtWegoDetails.Columns.Add("InboundflightNumber", System.Type.GetType("System.String"));
            dtWegoDetails.Columns.Add("InbounddepartureStation", System.Type.GetType("System.String"));
            dtWegoDetails.Columns.Add("InboundpassengerSTD", System.Type.GetType("System.String"));
            dtWegoDetails.Columns.Add("InboundUTCLocalDepartureTimeVariation", System.Type.GetType("System.String"));
            dtWegoDetails.Columns.Add("InboundpassengerDepartureTerminal", System.Type.GetType("System.String"));
            dtWegoDetails.Columns.Add("InboundarrivalStation", System.Type.GetType("System.String"));
            dtWegoDetails.Columns.Add("InboundSTA", System.Type.GetType("System.String"));
            dtWegoDetails.Columns.Add("InboundpassengerSTA", System.Type.GetType("System.String"));
            dtWegoDetails.Columns.Add("InboundUTCLocalArrivalTimeVariation", System.Type.GetType("System.String"));
            dtWegoDetails.Columns.Add("InboundaircraftType", System.Type.GetType("System.String"));
            dtWegoDetails.Columns.Add("InboundoperatorCode", System.Type.GetType("System.String"));
            dtWegoDetails.Columns.Add("InbounddurationInMin", System.Type.GetType("System.String"));
            dtWegoDetails.Columns.Add("InbounddepartureDateTime", System.Type.GetType("System.String"));
            dtWegoDetails.Columns.Add("InboundarrivalDateTime", System.Type.GetType("System.String"));

            return dtWegoDetails;
        }

        ///
        /// Gets the response.
        ///
        /// <param name="StrURL">The URL.
        /// HTML source
        private string GetResponse(string StrURL)
        {
            string strReturn = "";
            HttpWebRequest objRequest = null;
            IAsyncResult ar = null;
            HttpWebResponse objResponse = null;
            StreamReader objs = null;
            try
            {

                objRequest = (HttpWebRequest)WebRequest.Create(StrURL);
                objRequest.Method = "GET";
                objRequest.Referer = "http://www.comparexpress.com";
                objRequest.ReadWriteTimeout = 3600 * 1000;


                ar = objRequest.BeginGetResponse(new AsyncCallback(GetScrapingResponse), objRequest);

                //// Wait for request to complete

                ar.AsyncWaitHandle.WaitOne(1000 * 60, true);
                //ar.AsyncWaitHandle.WaitOne();
                if (objRequest.HaveResponse == false)
                {
                    throw new Exception("No Response!!!");
                }

                objResponse = (HttpWebResponse)objRequest.EndGetResponse(ar);

                objs = new StreamReader(objResponse.GetResponseStream());
                strReturn = objs.ReadToEnd();

            }
            catch (Exception exp)
            {
                throw exp;
            }
            finally
            {
                if (objResponse != null)
                    objResponse.Close();


                objs.Close();
                objRequest = null;
                ar = null;
                objResponse = null;
                objs = null;

            }
            return strReturn;
        }

        ///
        /// Gets the scraping response.
        ///
        /// &ltparam name="result">The result.
        protected void GetScrapingResponse(IAsyncResult result)
        {

        }

        private void CreateExceptionLog(Exception Ex, string strLocation)
        {
            String[] _fileContent = new String[6];
            _fileContent[0] = "Source : " + Ex.Source;
            _fileContent[1] = "Date Time : " + CE.Global.General.GetUTCDateTime().ToString();
            _fileContent[2] = "Stack Trace :" + Ex.StackTrace.ToString();
            _fileContent[3] = "Target Site : " + Ex.TargetSite.ToString();
            _fileContent[4] = "Location : " + "CE.Database.MyDatabase - " + strLocation;
            _fileContent[5] = "Message : " + Ex.Message;

            WriteExceptionLog("WegoFlights_", _fileContent);
        }

        private void WriteExceptionLog(string strPrefixFileName, string[] strException)
        {
            try
            {
                MyIO _newFile = new MyIO();
                string _filePath = AppDomain.CurrentDomain.BaseDirectory + "Exception\\";
                if (_newFile.CheckDirectory(_filePath))
                {
                    string _curMonth = CE.Global.General.GetUTCDateTime().Year.ToString("0000") + CE.Global.General.GetUTCDateTime().Month.ToString("00");

                    if (!_newFile.CheckDirectory(_filePath + _curMonth))
                    {
                        if (_newFile.CreateDirectory(_filePath, _curMonth))
                        {
                            _filePath += _curMonth + "\\";
                        }
                    }
                    else
                    {
                        _filePath += _curMonth + "\\";
                    }

                    string _fileName = strPrefixFileName + _curMonth + CE.Global.General.GetUTCDateTime().Day.ToString("00") + CE.Global.General.GetUTCDateTime().Second.ToString("00") + CE.Global.General.GetUTCDateTime().Millisecond.ToString("00") + ".txt";

                    _newFile.WriteNewFile(_filePath, _fileName, strException);
                    _newFile = null;
                }
            }
            catch (Exception Ex)
            {
                Ex = null;
            }
        }
    }
}

